<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TechNova - Appointment Service</title>
    <link rel="stylesheet" href="../css/styles.css">
</head>
<body>
    <div class="container">
        <!-- header.php -->
        <?php include '../common/header.php'; ?>
		
		<div class="appointment">
			<h1>Appointment Service</h1>
			<?php
			session_start();
			include '../dbconnect.php';
			// 检查用户是否已经登录
			if (!isset($_SESSION['uid']) || !isset($_SESSION['uname'])) {
				echo "请先登录！";
				exit;
			}
			$uid = $_SESSION['uid'];
			$uname = $_SESSION['uname'];
			// 从数据库中获取用户信息
			$sql = "SELECT * FROM user WHERE U_ID = ?";
			$stmt = $conn->prepare($sql);
			$stmt->bind_param("s", $uid);
			$stmt->execute();
			$result = $stmt->get_result();
			if ($result->num_rows > 0) {
				$row = $result->fetch_assoc();
				$name = $row['U_Username'];
				$email = $row['U_Email'];
			} else {
				$name = '';
				$email = '';
				$phone = '';
			}

			$stmt->close();
			$conn->close();
			
			// 连接到同一个数据库（假设 `select` 表也在同一个数据库中）
			$conn = new mysqli('localhost', 'root', 'root', 'bwd');
			if ($conn->connect_error) {
				die("Connection failed: " . $conn->connect_error);
			}

			// 从数据库中获取服务选项
			$sql_services = "SELECT * FROM services";
			$result_services = $conn->query($sql_services);
			$conn->close();
			?>
			<form action="submit_appointment.php" method="post">
				username : <input type="text" name="name" value="<?php echo htmlspecialchars($name); ?>" placeholder="Your Name" readonly>
				email : <input type="email" name="email" value="<?php echo htmlspecialchars($email); ?>" placeholder="Your Email" readonly>
				phone : <input type="tel" name="phone" value="<?php echo htmlspecialchars($phone); ?>" placeholder="Your Phone" required>
				type:
				<select name="service" required>
					 <?php
						if ($result_services->num_rows > 0) {
							while ($row_service = $result_services->fetch_assoc()) {
								echo "<option value='{$row_service['SERVICE_NAME']}'>{$row_service['SERVICE_NAME']}</option>";
							}
						}
					?>
				</select>
				message:<textarea name="message" placeholder="Please briefly describe your requirements" required></textarea>
				
				<input type="date" name="date" required>
				
				<button type="submit" class="button">Submit Appointment</button>
			</form>
			
		</div>
		
        <!--
        <div class="appointment">
            <h1>Appointment Service</h1>
            
            <form action="submit_appointment.php" method="post">
                <input type="text" name="name" placeholder="Your Name" required>
                <input type="email" name="email" placeholder="Your Email" required>
                <input type="tel" name="phone" placeholder="Your Phone" required>
                
                <select name="service" required>
                    <option value="">Select Service Type</option>
                    <option value="ai">Artificial Intelligence Solution</option>
                    <option value="blockchain">Blockchain Technology</option>
                    <option value="iot">Internet of Things Integration</option>
                </select>
                
                <textarea name="message" placeholder="Please briefly describe your requirements" required></textarea>
                
                <input type="date" required lang="en">
                
                <button type="submit" class="button">Submit Appointment</button>
            </form>
        </div>
		-->
		
		
    </div>
    
    <!-- footer.php -->
    <?php include '../common/footer.php'; ?>
</body>
</html>
